$(function () {

    //幻灯片初始化配置
    $(".swiper-container").swiper({
        autoplay: 3000,
        autoplayDisableOnInteraction: false,
        pagination : '.swiper-pagination',
        observer:true,
        observeParents:true,
    });

    new wLazyload({
        errorImage: staticPath + '/static/front/mobile/v3/img/default/error-pic.jpg', //图片加载失败点位图
        scrollEle: document.querySelector('.content') //滚动节点对象，默认为 window
    });

    $('body').on('click', '#swipe-banner .swiper-slide', function () {
        var direct = $(this).data('redirect');
        if (1 == direct) {
            window.location = '' + $(this).data('url');
        } else {
            if($(this).data('course')!=0){
                window.location = baseloaction + '/mobile/course/info?courseId=' + $(this).data('course');
            }

        }
    });

    //加载广告图片
    advertList();
    /**
     * 加载广告图片
     */
    function advertList() {
        $.ajax({
            url:baseloaction +'/mobile/course/advertList',
            type:'post',
            dataType:'json',
            data:{},
            success:function (result) {
                if(result.success==true){
                    var list = result.entity;
                    var context = '';
                    $.each(list,function (index,banner) {
                        context+='<div class="swiper-slide" data-course="'+banner.courseId+'" data-redirect="'+banner.redirectType+'" data-url="'+banner.pageUrl+'">';
                        context+='<img data-src="'+banner.imageMap.url+'" src="'+banner.imageMap.url+'" alt="'+banner.depict+'"/>';
                        context+='</div>';
                    });
                    $("#swipe-banner").html(context);
                }else{
                    $.toast(result.message);
                }
            },
            error:function (error) {
                
            }
        });
    }
});